package com.kifas.service.dataaccess;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kifas.entity.GudangEntity;

@Repository
public class GudangDao {

	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(GudangDao.class);

	@Autowired
	private SessionFactory sessionFactory;

	private static final String ALL_GUDANG = "FROM GudangEntity ";
	private static final String GUDANG_BY_ID = ALL_GUDANG + " where idGudang = :idGudang";

	@SuppressWarnings("unchecked")
	public List<GudangEntity> getGudangs() {
		return sessionFactory.getCurrentSession().createQuery(ALL_GUDANG).list();
	}

	public GudangEntity getGudang(Long idGudang) {
		return (GudangEntity) sessionFactory.getCurrentSession().createQuery(GUDANG_BY_ID).setParameter("idGudang", idGudang).uniqueResult();
	}

	public void insert(GudangEntity gudangEntity) throws Exception {
		sessionFactory.getCurrentSession().save(gudangEntity);
	}

	public void update(GudangEntity gudang) throws Exception {
		sessionFactory.getCurrentSession().update(gudang);
	}

}
